<template>
  <div class="bs" style="padding-bottom: 120px">
    <!-- 查询条件 -->
    <TableFilter :search-params.sync="tableParams" :items="searchForm">
      <template slot="suffix-button">
        <el-button type="danger" icon="el-icon-plus" @click="addJob('新增岗位')">新 增</el-button>
      </template>
    </TableFilter>
    <!-- table组件 -->
    <SrmTable
      ref="table"
      url="get|/trafficfly-manager/api/job"
      :is-load="true"
      :hidden="true"
      :table-attr="tableAttr"
      :params="tableParams"
      :columns="TableConfig"
      @tableOperate="callBack"
    />
    <Jop :show-jop.sync="showJop" :title="title" :edit-data="editData" @search="search" />
  </div>
</template>
<script>
import { searchForm } from './config/Search'
import { TableConfig } from './config/Table'
import Jop from './components/Jop'
import { del, edit } from '@/api/system/job'
export default {
  components: { Jop },
  data() {
    return {
      editData: {},
      title: '',
      showJop: false,
      tableAttr: { border: true },
      searchForm: searchForm,
      TableConfig: TableConfig,
      tableParams: {
        enabled: ''
      }
    }
  },
  methods: {
    search() {
      this.$refs.table.initTable()
    },
    callBack(v, d, n, t) {
      this[v](d, n, t)
    },
    addJob(t) {
      this.editData = {}
      this.title = t
      this.showJop = true
    },
    editJob(d, t) {
      this.editData = d
      this.title = t
      this.showJop = true
    },
    // updateStatus
    updateStatus(v) {
      this.$confirm(`此操作将 ${v.enabled ? '启用' : '停用'} ${v.name}, 是否继续？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        edit({ ...v }).then(res => {
          this.$message.success('操作成功~')
          this.$refs.table.initTable()
        }).catch(() => {
          v.enabled = !v.enabled
        })
      }).catch(() => {
        v.enabled = !v.enabled
      })
    },
    // delet
    delet(row) {
      this.$confirm('确定要删除该岗位吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        del([row.id]).then(res => {
          this.$message.success('操作成功~')
          this.$refs.table.initTable()
        })
      })
    }
  }
}
</script>
